package com.googlecode.iant.internal.dom;

import org.w3c.dom.Attr;

import com.googlecode.iant.dom.IXmlAttribute;

/**
	 * @author ccPascu
	 *
	 */
	public class XmlAttribute implements IXmlAttribute {

		private Attr attribute;

		public XmlAttribute(Attr attribute) {
			this.attribute = attribute;
		}

		/* (non-Javadoc)
		 * @see com.axway.ms.internal.dom.IXmlHelper.IXmlAttribute#as(java.lang.Object)
		 */
		@SuppressWarnings("unchecked")
		public <T> T as(Class<T> type) {
			final String value = attribute.getValue();
			if (type.isAssignableFrom(String.class)) {
				return (T) value;
			} 
			return null;
		}

		/* (non-Javadoc)
		 * @see com.axway.ms.internal.dom.IXmlHelper.IXmlAttribute#defined()
		 */
		public boolean defined() {
			return attribute != null;
		}

		@Override
		public String value() {
			return attribute.getValue();
		}

	}